package net.zhengxinyun.performance.yunpian;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import com.yunpian.sdk.model.VoiceSend;
import net.zhengxinyun.performance.entity.EvaluateUserEntity;
import net.zhengxinyun.performance.filter.EvaluateUserFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.08.08
 */
@Component
public class YunpianService {


    private final static String apiKey= "b3232c91e3336d52ae80b73bb0a1cb91";

    /**
     * 发送短信验证码
     *
     * @return VoiceSend
     */
    public Result<SmsSingleSend> sendSmS(EvaluateUserFilter evaluateUserFilter){
        YunpianClient clnt = new YunpianClient(apiKey).init();
        //修改账户信息API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, evaluateUserFilter.getPhone());
        param.put(YunpianClient.TEXT, "【时事一点通】您的验证码是6666。如非本人操作，请忽略本短信");
        return clnt.sms().single_send(param);
        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()
        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*
    }

    /**
     * 发送语音验证码
     * @param ssUserValid 验证码表(t_ss_user_valid)
     * @return VoiceSend
     */
//    public Result<VoiceSend> sendSound(SsUserValid ssUserValid){
//        Map<String, String> param = clnt.newParam(2);
//        param.put(YunpianClient.MOBILE, ssUserValid.getMoblie());
//        param.put(YunpianClient.CODE, ssUserValid.getVaildCode());
//        return clnt.voice().send(param);
//    }

}
